
requirejs(['jquery', 'Util', 'bootstrap', 'metisMenu', 'slimScroll', 'inspinia', 'chosen'], function ($, Util) {

    (function () {
        $.getJSON('/static/js/cityData.min.json', function (ret) {
            var str = '';
            $.each(ret, function (i, item) {
                str += '<option value="' + item.n + '">' + item.n + '</option>';
            });

            $(str).appendTo($('#area-province-chosen'));

            $('.province-chosen-select').chosen({
                width: '100%',
                allow_single_deselect: true,
                disable_search_threshold: 10,
                no_results_text: "未找到对应省市!"
            }).change(function () {
                var province = $(this).val();
                $.each(ret, function (i, item) {
                    if (item.n == province) {
                        var tmp = '';
                        $.each(item.s, function (index, city) {
                            tmp += '<option value="' + city.n + '">' + city.n + '</option>';
                        });
                        $('.city-chosen-select').empty();
                        $(tmp).appendTo($('.city-chosen-select'));
                        $('.city-chosen-select').trigger("chosen:updated");
                    }
                });
            }).trigger('change');

            $('.city-chosen-select').chosen({
                width: '100%',
                allow_single_deselect: true,
                disable_search_threshold: 10,
                no_results_text: "未找到对应省市!"
            }).change(function () {
                $('#cityData').val(($(this).val()).join(','));
            });

        });
    })();

    if ($('#is-success').val() == 1) {
        $('form')[0].reset();
        Util.Alert('新增成功!');
    }

});